package com.gateway.utils;

import lombok.Data;
import java.io.Serializable;

/**
 * 全局统一返回结构
 */
@Data
public class Result<T>implements Serializable {


    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回消息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;



    protected static <T> Result<T> build(T data){
        Result<T> result= new Result<T>();
        if(data==null){
            result.setData(null);
        }else {
            result.setData(data);
        }
        return result;
    }


    public static <T> Result<T> build(Integer code,String message,T data){
        Result<T> result= build(null);
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> build(Integer code,String message){
        Result<T> result= build(null);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
